package fr.jade.resources.database;

import fr.jade.base.JadeBaseComponent;
import fr.jade.fraclite.api.control.NoSuchAttributeException;
import fr.jade.resources.api.DataBase;

public class DataBaseWrapper extends JadeBaseComponent implements DataBase {

  // Attributes
  protected static final String dbNameAttName = "dbname";
  protected String dbName = null;
  
  protected static final String dbPathAttName = "dbpath";
  protected String dbPath = null;
  
  protected static final String[] attList = {dbNameAttName, dbPathAttName};
  
  // DataBase
  @Override
  public String getDataBaseName() {
    return dbName;
  }

  @Override
  public String getDataBasePath() {
    return dbPath;
  }

  // GenericAttributeController
  @Override
  public String getAttribute(String name) throws NoSuchAttributeException {
    if(name.equals(dbNameAttName)){
      return dbName;
    }else if(name.equals(dbPathAttName)){
      return dbPath;
    }else{
      return super.getAttribute(name);
    }
  }

  @Override
  public String[] listFcAtt() {
    return super.concat(attList, super.listFcAtt());
  }

  @Override
  public void setAttribute(String name, String value) throws NoSuchAttributeException {
    if(name.equals(dbNameAttName)){
      dbName = value;;
    }else if(name.equals(dbPathAttName)){
      dbPath = value;
    }else{
      super.setAttribute(name, value);
    }
  }

  
}
